package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //粉刷房子
    public int minCost(int[][] costs) {
        int n = costs.length;
        int[] red = new int[n]; red[0] = costs[0][0];
        int[] blue = new int[n]; blue[0] = costs[0][1];
        int[] green = new int[n]; green[0] = costs [0][2];
        if(n==1){
            return Math.min(red[0],Math.min(blue[0],green[0]));
        }
        for (int i = 1; i < n; i++) {
            red[i] = Math.min(blue[i-1],green[i-1]) + costs[i][0];
            blue[i] = Math.min(red[i-1],green[i-1]) + costs[i][1];
            green[i] = Math.min(red[i-1],blue[i-1]) + costs[i][2];
        }
        return Math.min(red[n-1],Math.min(blue[n-1],green[n-1]));
    }
}












